<?php
class Modelgis extends ModelBase1 {
	private $_uid = 0;
	private $_vin = 0;
	protected $tablename = '';
	
	
	private $data=null;
	/**
	 *
	 * @var CDbConnection
	 */
	function init(){
		global $_SGLOBAL;
		$this->_uid = $_SGLOBAL['uid'];
		$this->_vin = $_SGLOBAL['vincode'];
		$this->baseurl=$_SERVER['SERVER_NAME']."?path=services&action=gis";
		$this->shUrl = $_SERVER['SERVER_NAME']."?path=services&action=sh";
	}
	
	public function savePoiPointPost($data){
		$data = $this->splitJson($data['_data']);
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
		return $result;
	}
	// 获取收藏位置点
	public function getPoiPoint(){
		$data = array();
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
		return $result;
	}
	// 删除收藏位置点
	public function deletePoiPoint($data){
		$poiid = $data['poiid'];
		$data = array();
		$data['poiid'] = $poiid;
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
		return $result;
	}
	
	//保存已发送位置点
	public function saveSendPoiPoint($data){
		$data = $this->splitJson($data['_data']);
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$req = array();
		$req['pushObjectPoi'] = array("name"=>$data['name'],"lon"=>$data['longitude'],"lat"=>$data['latitude'],"tel"=>$data['telephone'],"shifted"=>false);
		$req['timeToDiscard'] = date('Y-m-d H:i:s');
		$result = requestserver($this->shUrl."&method=pushPOI",array('data'=>json_encode($req)),'post');
		$json = json_decode($result);
		if( $json && $json->eventIdStatus->status->code == 200 ){
			$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
			return $result;
		}else{
			echo "{code:0,description:'位置点发送失败'}";	
		}
	}
	//返回已发送位置点
	public function getSendPoiPoint(){
		$data = array();
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
		return $result;
	}
	//删除已发送位置点
	public function deleteSendPoiPoint($data){
		$sendid = $data['sendid'];
		$data = array();
		$data['sendid'] = $sendid;
		$data['uid'] = $this->_uid;
		$data['vin'] = $this->_vin;
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array('data'=>json_encode($data)),'post');
		return $result;
	}
	
	//获取省份
	public function getPrvoince(){
		$result = requestserver($this->baseurl."&method=".__FUNCTION__,array(),'get');
		return $result;
	}
	//获取城市
	public function getCity($adcode){
		$result = requestserver($this->baseurl."&method=".__FUNCTION__."&adcode=".$adcode,array(),'get');
		return $result;
	}
	private function splitJson($str){
		$str = substr($str , 1,strlen($str)-2);
		$strs = explode(',',$str);
		$ret = array();
		for( $i=0;$i<count($strs);$i++ ){
			$_t = explode(':',$strs[$i]);
			$ret[trim($_t[0],"'")] = trim($_t[1],"'");
		}
		return $ret;
	}
}
?>
